

//返回当前path 路径值 selectedKeys  openKeys
export function getDefaultKes(path,menuList){
  let result=[];
  assembleTree(menuList,result);
  let res=result.reduce((prev, cur, index, arr)=>{
    let i=cur.findIndex(item=>{return item.path==path})
    let res={index:index,i:i}
    return index==1?res:(res.i>prev.i?res:prev)
  })
  let array=result[res.index];
  let keys={'openKeys':[],'selectedKeys':[],'reFresh':true}
  for(let i=0;i<array.length;i++){
    if(i==array.length-1){
      keys.selectedKeys.push(array[i].name)
    }else {
      keys.openKeys.push(array[i].name)
    }
  }
  return keys;
}

//遍历所有路径情况
export function assembleTree(nodes,result,parent, depth) {
  if(!depth) depth = 0
  nodes.forEach(n => {
    let path = parent?parent.concat([{'name':n.name,'path':n.path}]):[{'name':n.name,'path':n.path}] // 按照顺序排列
    n.meta = {name: n.name, role: n.name, path: path}
    if (n.children && n.children instanceof Array) {
      assembleTree(n.children,result,path, depth)
    }else {
      result.push(path);
    }
  })
  if (depth === 0) {
    return nodes
  }
  depth++
}
